<?php
namespace app\index\model;
use app\index\model\Common;

class Yunpian{
    private $apikey;
    //
    public static function instance($apikey){
        return new Yunpian($apikey);
    }
    //
    public function __construct($apikey) {
        $this->apikey = $apikey;
    }
    /**
     * 云片发送国内短信
     * @param type $mobile 手机号
     * @param type $text 短信内容
     * @return type [code=>0, msg=>'']
     */
    public function send($mobile, $text){
        $header = [
            'Accept:application/json;charset=utf-8;',
            'Content-Type:application/x-www-form-urlencoded;charset=utf-8;'
        ];
        $url = 'https://sms.yunpian.com/v2/sms/single_send.json';
        $data = ['apikey'=>$this->apikey, 'mobile'=>$mobile, 'text'=>$text];
        $result = Common::instance()->postData($url, $data, $header);
        //$result = json_decode($json, true);
        return $result;
    }
}